home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GEN32.PAK / ABOUT.C next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  273 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   about.c
  9. //
  10. //  PURPOSE:   Displays the "About" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdAbout        - Displays the "About" dialog box
  14. //    About           - Processes messages for "About" dialog box.
  15. //    MsgAboutInit    - To initialize the about box with version info
  16. //                      from resources.
  17. //    MsgAboutCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdAboutDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include "globals.h"            // prototypes specific to this application
  26.  
  27. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  28. LRESULT MsgAboutInit(HWND, UINT, WPARAM, LPARAM);
  29. LRESULT MsgAboutCommand(HWND, UINT, WPARAM, LPARAM);
  30. LRESULT CmdAboutDone(HWND, WORD, WORD, HWND);
  31.  
  32. // About dialog message table definition.
  33. MSD rgmsdAbout[] =
  34. {
  35.     {WM_COMMAND,    MsgAboutCommand},
  36.     {WM_INITDIALOG, MsgAboutInit}
  37. };
  38.  
  39. MSDI msdiAbout =
  40. {
  41.     sizeof(rgmsdAbout) / sizeof(MSD),
  42.     rgmsdAbout,
  43.     edwpNone
  44. };
  45.  
  46. // About dialog command table definition.
  47. CMD rgcmdAbout[] =
  48. {
  49.     {IDOK,     CmdAboutDone},
  50.     {IDCANCEL, CmdAboutDone}
  51. };
  52.  
  53. CMDI cmdiAbout =
  54. {
  55.     sizeof(rgcmdAbout) / sizeof(CMD),
  56.     rgcmdAbout,
  57.     edwpNone
  58. };
  59.  
  60. // Module specific "globals"  Used when a variable needs to be
  61. // accessed in more than on handler function.
  62.  
  63. HFONT hFontCopyright;
  64.  
  65. //
  66. //  FUNCTION: CmdAbout(HWND, WORD, WORD, HWND)
  67. //
  68. //  PURPOSE: Displays the "About" dialog box
  69. //
  70. //  PARAMETERS:
  71. //    hwnd      - Window handle
  72. //    wCommand  - IDM_ABOUT (unused)
  73. //    wNotify   - Notification number (unused)
  74. //    hwndCtrl  - NULL (unused)
  75. //
  76. //  RETURN VALUE:
  77. //
  78. //    Always returns 0 - Message handled
  79. //
  80. //  COMMENTS:
  81. //    To process the IDM_ABOUT message, call DialogBox() to display the
  82. //    about dialog box.
  83.  
  84. #pragma argsused
  85. LRESULT CmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  86. {
  87.     DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
  88.     return 0;
  89. }
  90.  
  91.  
  92. //
  93. //  FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
  94. //
  95. //  PURPOSE:  Processes messages for "About" dialog box.
  96. //
  97. //  PARAMETERS:
  98. //    hdlg - window handle of the dialog box
  99. //    wMessage - type of message
  100. //    wparam - message-specific information
  101. //    lparam - message-specific information
  102. //
  103. //  RETURN VALUE:
  104. //    TRUE - message handled
  105. //    FALSE - message not handled
  106. //
  107. //  COMMENTS:
  108. //
  109. //     Display version information from the version section of the
  110. //     application resource.
  111. //
  112. //     Wait for user to click on "Ok" button, then close the dialog box.
  113. //
  114.  
  115. LRESULT CALLBACK About(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  116. {
  117.     return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
  118. }
  119.  
  120.  
  121. //
  122. //  FUNCTION: MsgAboutInit(HWND, UINT, WPARAM, LPARAM)
  123. //
  124. //  PURPOSE: To initialize the about box with version info from resources.
  125. //
  126. //  PARAMETERS:
  127. //    hwnd - The window handing the message.
  128. //    uMessage - The message number. (unused).
  129. //    wparam - Message specific data (unused).
  130. //    lparam - Message specific data (unused).
  131. //
  132. //  RETURN VALUE:
  133. //    Always returns 0 - message handled.
  134. //
  135. //  COMMENTS:
  136. //    Uses the version apis to retrieve version information for
  137. //    each of the static text boxes in the about box.
  138. //
  139.  
  140. #pragma argsused
  141. LRESULT MsgAboutInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  142. {
  143.     #define POINTSIZE 8
  144.  
  145.     char  szFullPath[256];
  146.     DWORD dwVerHnd;
  147.     DWORD dwVerInfoSize;
  148.     HDC   hDC;
  149.     int   iLogPixelsY, iPointSize;
  150.  
  151.     // Center the dialog over the application window
  152.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  153.  
  154.     // Set the copyright font to something smaller than default
  155.     hDC = GetDC(hdlg);
  156.     iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
  157.     ReleaseDC(hdlg, hDC);
  158.     iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
  159.     iPointSize *= -1;
  160.  
  161.     hFontCopyright = CreateFont(iPointSize,
  162.                                 0, 0, 0,
  163.                                 FW_BOLD,
  164.                                 0, 0, 0, 0,
  165.                                 0, 0, 0, 0,
  166.                                 "Arial");
  167.  
  168.     SendDlgItemMessage(hdlg, 
  169.                        IDD_VERLAST, 
  170.                        WM_SETFONT, 
  171.                        (WPARAM)hFontCopyright,
  172.                        0L);
  173.  
  174.     // Get version information from the application
  175.     GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
  176.     dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
  177.     if (dwVerInfoSize)
  178.     {
  179.         // If we were able to get the information, process it:
  180.         HANDLE  hMem;
  181.         LPVOID  lpvMem;
  182.         char    szGetName[256];
  183.         int     cchRoot;
  184.         int     i;
  185.  
  186.         hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  187.         lpvMem = GlobalLock(hMem);
  188.         GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
  189.         lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
  190.         cchRoot = lstrlen(szGetName);
  191.  
  192.         // Walk through the dialog items that we want to replace:
  193.         for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
  194.         {
  195.             BOOL  fRet;
  196.             UINT  cchVer = 0;
  197.             LPSTR lszVer = NULL;
  198.             char  szResult[256];
  199.  
  200.             GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
  201.             lstrcpy(&szGetName[cchRoot], szResult);
  202.             fRet = VerQueryValue(lpvMem, szGetName, (LPVOID) &lszVer, &cchVer);
  203.  
  204.             if (fRet && cchVer && lszVer)
  205.             {
  206.                 // Replace dialog item text with version info
  207.                 lstrcpy(szResult, lszVer);
  208.                 SetDlgItemText(hdlg, i, szResult);
  209.             }
  210.         }
  211.         GlobalUnlock(hMem);
  212.         GlobalFree(hMem);
  213.     }
  214.     return TRUE;
  215. }
  216.  
  217. //
  218. //  FUNCTION: MsgAboutCommand(HWND, UINT, WPARAM, LPARAM)
  219. //
  220. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  221. //
  222. //  PARAMETERS:
  223. //    hwnd - The window handing the message.
  224. //    uMessage - The message number. (unused).
  225. //    wparam - Message specific data (unused).
  226. //    lparam - Message specific data (unused).
  227. //
  228. //  RETURN VALUE:
  229. //    Always returns 0 - message handled.
  230. //
  231. //  COMMENTS:
  232. //    Uses this DipsCommand function defined in wndproc.c combined
  233. //    with the cmdiAbout structure defined in this file to handle
  234. //    the command messages for the about dialog box.
  235. //
  236.  
  237. #pragma argsused
  238. LRESULT MsgAboutCommand(HWND   hwnd, 
  239.                         UINT   uMessage, 
  240.                         WPARAM wparam, 
  241.                         LPARAM lparam)
  242. {
  243.     return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
  244. }
  245.  
  246. //
  247. //  FUNCTION: CmdAboutDone(HWND, WORD, HWND)
  248. //
  249. //  PURPOSE: Free the about box and related data.
  250. //
  251. //  PARAMETERS:
  252. //    hwnd - The window handling the command.
  253. //    wCommand - The command to be handled (unused).
  254. //    wNotify   - Notification number (unused)
  255. //    hwndCtrl - NULL (unused).
  256. //
  257. //  RETURN VALUE:
  258. //    Always returns TRUE.
  259. //
  260. //  COMMENTS:
  261. //    Calls EndDialog to finish the dialog session.
  262. //
  263.  
  264. #pragma argsused
  265. LRESULT CmdAboutDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  266. {
  267.     if (hFontCopyright)
  268.        DeleteObject(hFontCopyright);
  269.  
  270.     EndDialog(hdlg, TRUE);          // Exit the dialog
  271.     return TRUE;
  272. }
  273.